/*****************************************************************************
*Purpose: Format Tables and populate them with disclosed estimates
******************************************************************************/ 

// Table 1: Balance Table  / Summary stats

import delimited "$dir\Collinson_GAUMTO3_Table2_BALKIDS_T13_rounded.csv", varnames(2) clear 
rename source sourcedata
tempfile balkids
save `balkids'

import delimited "$dir\Collinson_GAUMTO_Table14_CEN00MOVERS_T13_rounded.csv", clear 
append using `balkids'

*renaming because locals are too long
replace spec ="stdpovrt" if spec =="std_place_povrate"
replace spec ="stdwt" if spec =="std_place_shwhite"
replace spec ="stdfam" if spec =="std_place_shafam"
replace outcome ="prpctblk" if outcome =="prm2019_pctblack"



*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01


** drop stuff i dont need 
keep if inlist(group, "all")

replace sourcedata = "c" if sourcedata== "CEN00MAFARF"
replace sourcedata = "b" if sourcedata == "BALANCE"

** defining locals in loops 
levelsof sourcedata, local(data)
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

*need separate local for earnings because don't need 3 decimals
local outcomes2 "prearn24"
local data2 "b"

	// beta 

foreach data in `data'  {
	local id0 = "`data'"
	
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								 spec == "`spex'" 
				local `id0'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}

	// beta 

foreach data in `data2'  {
	local id0 = "`data'"
	
foreach outx in `outcomes2' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								 spec == "`spex'" 
				local `id0'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}

	

	
* doing earnings and income manually cause no decimals 
global y "emp w_wage w_inc inc"
global sp "meansd diff"
global s "c b"

foreach i in $s {   
foreach x in $y {
	
	foreach z in $sp  {
		
		sum beta if sourcedata == "`i'" & ///
					outcome == "`x'" & ///
					spec == "`z'"
		global `i'_`x'_`z'_b : di string(r(mean), "%9.0fc")
		
		sum se if sourcedata == "`i'" & ///
					outcome == "`x'" & ///
					spec == "`z'"
		global `i'_`x'_`z'_se : di string(r(mean), "%9.0fc")
	} 
	 		
}
}



* making gautreaux income annual: 
sum beta if sourcedata == "b" & outcome == "inc" & spec == "meansd"
global inc_meansd_b: di r(mean)
sum se if sourcedata == "b" & outcome == "inc" & spec == "meansd"
global inc_meansd_se: di r(mean)

sum beta if sourcedata == "b" & outcome == "inc" & spec == "diff"
global inc_diff_b: di r(mean)
sum se if sourcedata == "b" & outcome == "inc" & spec == "diff"
global inc_diff_se: di r(mean)

local ann_inc_meansd_b =string(($inc_meansd_b*12), "%9.0fc" )  
local ann_inc_meansd_se =string(($inc_meansd_se*12), "%9.0fc" )  
local ann_inc_diff_b =string(($inc_diff_b*12), "%9.0fc" ) 
local ann_inc_diff_se =string(($inc_diff_se*12), "%9.0fc" )  


* Fstat/ pvale
sum beta if spec == "Fstat_pval"
global fstat : di string(r(mean), "%9.3fc")

sum se if spec == "Fstat_pval" & sourcedata == "b"
global b_fstat_p : di string(r(mean), "%9.3fc")

sum se if spec == "Fstat_pval" & sourcedata == "c"
global c_fstat_p : di string(r(mean), "%9.3fc")



*******************************
*********** Table I ***********
*******************************

	
texdoc init "$results\Table_1.tex", replace force
tex {
tex \begin{tabular}{lccccccc} \toprule 
tex & (1) & & (2) & & (3) & & (4) \\ \\[-1.5ex]
tex & \multicolumn{3}{c}{\shortstack{2000 Census Sample \\ \\ (Endogenous Movers)}} & & \multicolumn{3}{c}{Gautreaux} \\ 
tex \cmidrule{2-4} \cmidrule{6-8} \\[-1.75ex]
tex & \shortstack{Control \\ Mean} & & Est. & & \shortstack{Control \\ Mean} & & Est. \\
tex \midrule
tex Panel A. Household Heads: & & & & & \\ \\[-1.5ex]
tex \quad Female  & `c_female_meansd_b' &   &  `c_female_diff_b'`c_female_diff_str' & & `b_head_female_meansd_b' &   &  `b_head_female_diff_b'`b_head_female_diff_str' \\
tex		& (`c_female_meansd_se') &	& (`c_female_diff_se') &	& (`b_head_female_meansd_se') &	& (`b_head_female_diff_se') \\ \\ [-2.25ex] 
tex \quad Age & `c_qage_meansd_b' &  &  `c_qage_diff_b'`c_qage_diff_str'  &  & `b_headage_meansd_b' &  &  `b_headage_diff_b'`b_headage_diff_str'  \\
tex		&(`c_qage_meansd_se') &	&(`c_qage_diff_se') &	&(`b_headage_meansd_se') &	&(`b_headage_diff_se') \\ \\ [-2.25ex] 
tex \quad Has Car  & `c_hascar_meansd_b' &   &  `c_hascar_diff_b'`c_hascar_diff_str' & & `b_auto_meansd_b' &   &  `b_auto_diff_b'`b_auto_diff_str' \\ 
tex		& (`c_hascar_meansd_se') &	& (`c_hascar_diff_se') &		& (`b_auto_meansd_se') &	& (`b_auto_diff_se') \\ \\ [-2.25ex] 
tex \quad Married     & `c_married_meansd_b' &  & `c_married_diff_b'`c_married_diff_str' & & `b_married_meansd_b' &  & `b_married_diff_b'`b_married_diff_str' \\
tex		&(`c_married_meansd_se')&	&(`c_married_diff_se') &	&(`b_married_meansd_se')&	&(`b_married_diff_se') \\ \\ [-2.25ex] 	
tex \quad Working & `c_employed_meansd_b' &  &  `c_employed_diff_b'`c_employed_diff_str'  & & `b_work_meansd_b' &  &  `b_work_diff_b'`b_work_diff_str'  \\
tex &(`c_employed_meansd_se') & & (`c_employed_diff_se')& &(`b_work_meansd_se') & & (`b_work_diff_se') \\ \\ [-2.25ex] 
tex \quad Earnings & ${c_w_wage_meansd_b} &  &  ${c_w_wage_diff_b}`c_w_wage_diff_str'  & & ${b_emp_meansd_b} &  &  ${b_emp_diff_b}`b_emp_diff_str'  \\
tex &(${c_w_wage_meansd_se}) & & (${c_w_wage_diff_se})&  &(${b_emp_meansd_se}) & & (${b_emp_diff_se}) \\ \\ [-2.25ex] 
tex \quad Annual Income & ${c_w_inc_meansd_b} &  &  ${c_w_inc_diff_b}`c_w_inc_diff_str'& & `ann_inc_meansd_b' &  & `ann_inc_diff_b'`b_inc_diff_str' \\
tex &(${c_w_inc_meansd_se}) & & (${c_w_inc_diff_se})& &(`ann_inc_meansd_se') & & (`ann_inc_diff_se') \\ \\ [-2.25ex] 
tex \quad \# Bedrooms Needed & `c_bedneed_meansd_b' &  &  `c_bedneed_diff_b'`c_bedneed_diff_str'&  & `b_bed_meansd_b' &  &  `b_bed_diff_b'`b_bed_diff_str' \\
tex &(`c_bedneed_meansd_se') & & (`c_bedneed_diff_se')&  &(`b_bed_meansd_se') & & (`b_bed_diff_se') \\ \\ [-2.25ex] 
tex \quad Public Housing & &  &   &  & `b_ph_meansd_b' &  &  `b_ph_diff_b'`b_ph_diff_str'  \\
tex & & & & &(`b_ph_meansd_se') & & (`b_ph_diff_se') \\ \\ [-2.25ex] 
tex \quad Has License & &  &    & & `b_license_meansd_b' &  &  `b_license_diff_b'`b_license_diff_str'  \\
tex & & & &  &(`b_license_meansd_se') & & (`b_license_diff_se') \\ \\ [-2.25ex] 
tex Panel B. Children & & & & & & & \\ \\[-1.5ex]
tex \quad Female  & &   & & &`b_female_meansd_b'&   & `b_female_diff_b'`b_female_diff_str'  \\
tex		& &	& &	&(`b_female_meansd_se') &	&(`b_female_diff_se') \\ \\ [-2.25ex] 
tex \quad Age &  &  &  &    & `b_ageatintake_meansd_b' &  & `b_ageatintake_diff_b'`b_ageatintake_diff_str' \\
tex		& &	& &	&(`b_ageatintake_meansd_se')&	&(`b_ageatintake_diff_se') \\ \\ [-2.25ex] 
tex \quad Born in Chicago &  &  &   & & `b_chicago_meansd_b' &  &  `b_chicago_diff_b'`b_chicago_diff_str'  \\ 
tex & & & & &(`b_chicago_meansd_se') & & (`b_chicago_diff_se') \\ \\[-1.5ex]
tex \quad Predicted Later-life Earnings &  &  &   & & `b_prearn24_meansd_b' &  &  `b_prearn24_diff_b'`b_prearn24_diff_str'  \\ 
tex & & & & &(`b_prearn24_meansd_se') & & (`b_prearn24_diff_se') \\ \\[-1.5ex]
tex \quad Predicted Later-life Share Black &  &  &   & & `b_prpctblk_meansd_b' &  &  `b_prpctblk_diff_b'`b_prpctblk_diff_str'  \\ 
tex & & & & &(`b_prpctblk_meansd_se') & & (`b_prpctblk_diff_se') \\ \\[-1.5ex]
tex Sample Size &  & & `c_diff_n' & &  & & `b_diff_n' \\
tex \quad \$p\$-value (Joint Orthogonality) & & & ${c_fstat_p} &  & & & ${b_fstat_p} \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close





// Table 2: Economic Outcomes

import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

keep if source =="BASE" & group =="all"
keep if spec =="base" | spec =="meansd"
rename source sourcedata 

preserve
	import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear 
	*keep what I need
	keep if inlist(outcome, "owner_2010", "own20172019", "avgown20172019")
	keep if inlist(spec, "meansd", "notractfe", "nocont", "base")
	keep if group=="35andolder"
	tempfile c2010_data
	save `c2010_data'
restore
append using `c2010_data'

preserve
	import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 
	*keep what I need
	keep if inlist(outcome, "owner_2010", "own20172019", "avgown20172019")
	keep if inlist(spec, "meansd", "notractfe", "nocont", "base")
	keep if group=="35andolder"
	tempfile marfar
	save `marfar'
restore
append using `marfar'

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

local outcomes1 "avgearn2428 avgearn2933 avgearn3438 cumul_earn28 cumul_earn33 cumul_earn38"
local outcomes2 "owner_2010 own20172019 avgown20172019"

	// beta 
foreach outx in `outcomes1' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

// beta 
foreach outx in `outcomes2' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}
	
*******************************
********* Table III ***********
*******************************

	
texdoc init "$results\Table_3.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{l C{2.35cm} C{2.35cm} C{2.35cm}} \toprule 
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{Outcome: Earnings at...} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Ages \\ 24-28} & \shortstack{Ages \\ 29-33} & \shortstack{Ages \\ 34-38} \\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`avgearn2428_base_b'`avgearn2428_base_str' &`avgearn2933_base_b'`avgearn2933_base_str' &`avgearn3438_base_b'`avgearn3438_base_str'\\
tex &(`avgearn2428_base_se') &(`avgearn2933_base_se') &(`avgearn3438_base_se')\\\\
tex Control Mean &`avgearn2428_meansd_b' &`avgearn2933_meansd_b' &`avgearn3438_meansd_b'\\
tex Control SD &`avgearn2428_meansd_se' &`avgearn2933_meansd_se' &`avgearn3438_meansd_se'\\
tex Sample Size &`avgearn2428_base_n' &`avgearn2933_base_n' &`avgearn3438_base_n'\\
tex \midrule \\[-0.5ex]
tex &\multicolumn{3}{c}{Outcome: Cumulative Earnings by...} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Age 28} &\shortstack{Age 33} &\shortstack{Age 38} \\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`cumul_earn28_base_b'`cumul_earn28_base_str' &`cumul_earn33_base_b'`cumul_earn33_base_str' &`cumul_earn38_base_b'`cumul_earn38_base_str'\\
tex &(`cumul_earn28_base_se') &(`cumul_earn33_base_se') &(`cumul_earn38_base_se')\\\\
tex Control Mean &`cumul_earn28_meansd_b' &`cumul_earn33_meansd_b' &`cumul_earn38_meansd_b'\\
tex Control SD &`cumul_earn28_meansd_se' &`cumul_earn33_meansd_se' &`cumul_earn38_meansd_se'\\
tex Sample Size &`cumul_earn28_base_n' &`cumul_earn33_base_n' &`cumul_earn38_base_n'\\
tex \midrule \\[-0.5ex]
tex &\multicolumn{3}{c}{Outcome: Homeownership} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Owner} &\shortstack{Ever \\ \\ Owner- \\ \\  Occupied} &\shortstack{Share \\ \\ of Years \\ \\ Owner- \\ \\ Occupied}\\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`owner_2010_base_b'`owner_2010_base_str' &`own20172019_base_b'`own20172019_base_str' &`avgown20172019_base_b'`avgown20172019_base_str'\\
tex &(`owner_2010_base_se') &(`own20172019_base_se') &(`avgown20172019_base_se')\\\\
tex Control Mean &`owner_2010_meansd_b' &`own20172019_meansd_b' &`avgown20172019_meansd_b'\\
tex Control SD &`owner_2010_meansd_se' &`own20172019_meansd_se' &`avgown20172019_meansd_se'\\
tex Sample Size &`owner_2010_base_n' &`own20172019_base_n' &`avgown20172019_base_n'\\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


// Table 4: HH FE
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

*rename for locals
replace spec ="hhfe_byt" if spec =="hhfe_binary_youngerTreat"
replace spec ="hhfe_caxt" if spec =="hhfe_continuous_ageXtreat"
rename source sourcedata
replace sourcedata ="b" if sourcedata =="BASE"
replace sourcedata ="h" if sourcedata =="HHFE"

*keep what I need
keep if group =="all"
keep if spec =="hhfe_byt" | spec =="hhfe_caxt" | spec =="meansd"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof sourcedata, local(data)
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 

foreach data in `data'  {
	local id0 = "`data'"
	
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								 outcome == "`outx'" & ///
								 spec == "`spex'",
				local `id0'_`id1'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}

*******************************
********* Table VII ***********
*******************************


texdoc init "$results\Table_7.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccccc} \toprule 
tex & (1) & (2) & (3) & (4) \\ \\[-1.5ex]
tex & \multicolumn{4}{c}{Outcome: Earnings at...} \\
tex \cmidrule{2-5} \\[-1ex]
tex &\shortstack{Ages \\ \\ 24-28} &\shortstack{Ages \\ \\ 26-28} & \shortstack{Ages \\ \\ 29-33} &\shortstack{Cumulative \\ \\ by Age 28} \\ \\[-1.75ex]
tex \midrule
tex Panel A. Binary Exposure \\ \\[-1.5ex]
tex \quad 1(\% Black $<$ 30) $\times$ 1(\text{Age<10}) &`h_avgearn2428_hhfe_byt_b'`h_avgearn2428_hhfe_byt_str' &`h_avgearn2628_hhfe_byt_b'`h_avgearn2628_hhfe_byt_str' &`h_avgearn2933_hhfe_byt_b'`h_avgearn2933_hhfe_byt_str' &`h_cumul_earn28_hhfe_byt_b'`h_cumul_earn28_hhfe_byt_str'\\
tex &(`h_avgearn2428_hhfe_byt_se') &(`h_avgearn2628_hhfe_byt_se') &(`h_avgearn2933_hhfe_byt_se') &(`h_cumul_earn28_hhfe_byt_se')\\\\[-1.5ex]
tex Panel B. Linear Exposure \\ \\[-1.5ex]
tex \quad 1(\% Black $<$ 30) $\times$ \text{Age} &`h_avgearn2428_hhfe_caxt_b'`h_avgearn2428_hhfe_caxt_str' &`h_avgearn2628_hhfe_caxt_b'`h_avgearn2628_hhfe_caxt_str' &`h_avgearn2933_hhfe_caxt_b'`h_avgearn2933_hhfe_caxt_str' &`h_cumul_earn28_hhfe_caxt_b'`h_cumul_earn28_hhfe_caxt_str'\\
tex &(`h_avgearn2428_hhfe_caxt_se') &(`h_avgearn2628_hhfe_caxt_se') &(`h_avgearn2933_hhfe_caxt_se') &(`h_cumul_earn28_hhfe_caxt_se')\\\\
tex Control Mean &`b_avgearn2428_meansd_b' &`b_avgearn2628_meansd_b' &`b_avgearn2933_meansd_b' &`b_cumul_earn28_meansd_b'\\
tex Control SD &`b_avgearn2428_meansd_se' &`b_avgearn2628_meansd_se' &`b_avgearn2933_meansd_se' &`b_cumul_earn28_meansd_se'\\
tex Sample Size &`h_avgearn2428_hhfe_caxt_n' &`h_avgearn2628_hhfe_caxt_n' &`h_avgearn2933_hhfe_caxt_n' &`h_cumul_earn28_hhfe_caxt_n'\\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


///Table 5: horse race shwhite
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear
rename source sourcedata

preserve
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded", clear 
tempfile mafar
save `mafar'
restore 
append using `mafar'

*rename for locals
replace spec ="swsw" if spec =="shwhite_shwhite" | spec =="Robustness: stdshwhite"
replace spec ="prpr" if spec =="povrate_povrate" | spec =="Robustness: stdpovrate"
replace spec ="prvswsw" if spec=="povrate_v_shwhite_shwhite" | spec =="Robustness: HRwhite_v_pov_betawhite"
replace spec ="prvswpr" if spec =="povrate_v_shwhite_povrate" | spec =="Robustness: HRwhite_v_pov_betapov"
replace sourcedata ="h" if sourcedata =="HR"
replace sourcedata ="m" if sourcedata =="MAFARF"

*keep what I need
keep if group =="all"
keep if sourcedata =="h" | sourcedata =="m"
keep if spec =="swsw" | spec =="prpr" | spec =="prvswsw" | spec =="prvswpr" | spec =="meansd"
drop if outcome =="m2010_incrnk_black" | outcome =="m2019_incrnk_black" | outcome =="sametractparent2019"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof sourcedata, local(data)
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

local outcomes1 "avgearn2428"
local data1 "h"
local outcomes2 "m2019_pctblack"
local data2 "m"
	// beta 

foreach data in `data1'  {
	local id0 = "`data'"
	
foreach outx in `outcomes1' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								 outcome == "`outx'" & ///
								 spec == "`spex'",
				local `id0'_`id1'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}

	// beta 

foreach data in `data2'  {
	local id0 = "`data'"
	
foreach outx in `outcomes2' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								 outcome == "`outx'" & ///
								 spec == "`spex'",
				local `id0'_`id1'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}

*******************************
*********** Table V ***********
*******************************

texdoc init "$results\Table_5.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcccc} \toprule 
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex & \multicolumn{3}{c}{\shortstack{Outcome: \\ \\ Earnings at Ages 24-28}} \\ \\[-2.5ex]
tex \midrule 
tex Share White (\$z\$-score) &`h_avgearn2428_swsw_b'`h_avgearn2428_swsw_str' & &`h_avgearn2428_prvswsw_b'`h_avgearn2428_prvswsw_str'\\
tex &(`h_avgearn2428_swsw_se') & &(`h_avgearn2428_prvswsw_se') \\
tex Poverty Rate (\$z\$-score) & &`h_avgearn2428_prpr_b'`h_avgearn2428_prpr_str' &`h_avgearn2428_prvswpr_b'`h_avgearn2428_prvswpr_str'\\
tex & &(`h_avgearn2428_prpr_se') &(`h_avgearn2428_prvswpr_se') \\\\
tex Sample Size &`h_avgearn2428_swsw_n' &`h_avgearn2428_prpr_n' &`h_avgearn2428_prvswsw_n' \\
tex \midrule \\[-0.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: Later-life \\ \\ Neighborhood Share Black}} \\ \\[-2.5ex]
tex \midrule
tex Share White (\$z\$-score) &`m_m2019_pctblack_swsw_b'`m_m2019_pctblack_swsw_str' & &`m_m2019_pctblack_prvswsw_b'`m_m2019_pctblack_prvswsw_str'\\
tex &(`m_m2019_pctblack_swsw_se') & &(`m_m2019_pctblack_prvswsw_se') \\
tex Poverty Rate (\$z\$-score) & &`m_m2019_pctblack_prpr_b'`m_m2019_pctblack_prpr_str' &`m_m2019_pctblack_prvswpr_b'`m_m2019_pctblack_prvswpr_str'\\
tex & &(`m_m2019_pctblack_prpr_se') &(`m_m2019_pctblack_prvswpr_se') \\\\
tex Sample Size &`m_m2019_pctblack_swsw_n' &`m_m2019_pctblack_prpr_n' &`m_m2019_pctblack_prvswsw_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close



///Table 4: Social Outcomes
**Table IV
import delimited "$dir\Collinson_GAUMTO_Table3_CEN00KIDS_T13_rounded.csv", clear 
tempfile c2000_data
save `c2000_data'

import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 
append using `c2000_data'
tempfile combined
save `combined'

import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear 
append using `combined'

** keep relevant observations 
keep if inlist(group, "all")
keep if inlist(outcome, "m2019_pctblack", "m2019_povrate", "m2019_pctwhite", "m2019_incrnk", "married_2010", "married_white", "refheadsps")
keep if inlist(spec, "meansd", "base")

*rename
replace sourcedata ="c10" if sourcedata =="CEN2010"
replace sourcedata ="c00" if sourcedata =="CEN2000"
replace sourcedata ="m" if sourcedata =="MAFARF"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

levelsof sourcedata, local(data)
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

// beta 

foreach data in `data'  {
	local id0 = "`data'"
	
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								outcome == "`outx'" & ///
								 spec == "`spex'" 
				local `id0'_`id1'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}
*******************************
********** Table IV ***********
*******************************

texdoc init "$results/Table_4.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccccccc} \toprule 
tex & (1) & (2) & (3) & (4) & & (5) & (6) \\ \\[-1.5ex]
tex &\multicolumn{4}{c}{\shortstack{Outcome: Later-life \\ \\ Neighborhood Characteristics}} & & \multicolumn{2}{c}{\shortstack{Outcome: \\ \\ Marriage}}\\
tex \cmidrule{2-5} \cmidrule{7-8}\\[-1.75ex]
tex &\shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\ White} & \shortstack{Poverty \\ \\ Rate} & \shortstack{Later-life \\ \\ Income \\ \\ Rank} & &\shortstack{Married} &\shortstack{Married \\ \\ White \\ \\ Spouse} \\ \\[-2.5ex] 
tex \midrule \\[-1.75ex]
tex $1(\mathit{Share Black}_{d(i)} < 0.30)$ &`m_m2019_pctblack_base_b'`m_m2019_pctblack_base_str' & `m_m2019_pctwhite_base_b'`m_m2019_pctwhite_base_str' &`m_m2019_povrate_base_b'`m_m2019_povrate_base_str' &`m_m2019_incrnk_base_b'`m_m2019_incrnk_base_str'& &`c10_married_2010_base_b'`c10_married_2010_base_str' &`c10_married_white_base_b'`c10_married_white_base_str' \\
tex &(`m_m2019_pctblack_base_se') &(`m_m2019_pctwhite_base_se') &(`m_m2019_povrate_base_se') &(`m_m2019_incrnk_base_se')& &(`c10_married_2010_base_se') &(`c10_married_white_base_se') \\\\
tex Control Mean &`m_m2019_pctblack_meansd_b' &`m_m2019_pctwhite_meansd_b' &`m_m2019_povrate_meansd_b' &`m_m2019_incrnk_meansd_b' & &`c10_married_2010_meansd_b' &`c10_married_white_meansd_b' \\
tex Sample Size &`m_m2019_pctblack_base_n' &`m_m2019_pctwhite_base_n' & `m_m2019_povrate_base_n' & `m_m2019_incrnk_base_n' & &`c10_married_2010_base_n' &`c10_married_white_base_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close




///Table 6: Parents
import delimited "$dir\Collinson_GAUMTO_Table8_LEHDHOH_T13_rounded.csv", clear 
tempfile leh
save `leh'

import delimited "$dir\Collinson_GAUMTO_Table11_CEN10HOH_T13_rounded.csv", clear 
append using `leh'
tempfile lehcen
save `lehcen'

import delimited "$dir\Collinson_GAUMTO_Table9_MAFARFHOH_T13_rounded.csv", clear 
append using `lehcen'

*keep what I need
keep if spec =="base" | spec =="meansd"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

local outcomes1 "avgearn3842 avgearn4347 avgearn4852"
local outcomes2 "m2019_pctblack m2019_pctwhite m2019_povrate married_2010 married_white owner_2010"

	// beta 
foreach outx in `outcomes1' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

	// beta 
foreach outx in `outcomes2' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

*******************************
********** Table VI ***********
*******************************

texdoc init "$results\Table_6.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcccc} \toprule 
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{Outcome: Earnings at...} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex & \shortstack{Ages \\ 38-42} & \shortstack{Ages \\ 43-47} & \shortstack{Ages \\ 48-52} \\ \\[-1.75ex]
tex \midrule
tex 1(\% Black < 30) &`avgearn3842_base_b'`avgearn3842_base_str' &`avgearn4347_base_b'`avgearn4347_base_str' &`avgearn4852_base_b'`avgearn4852_base_str'\\
tex &(`avgearn3842_base_se') &(`avgearn4347_base_se') &(`avgearn4852_base_se') \\\\
tex Control Mean &`avgearn3842_meansd_b' &`avgearn4347_meansd_b' &`avgearn4852_meansd_b' \\
tex Sample Size &`avgearn3842_base_n' &`avgearn4347_base_n' &`avgearn4852_base_n' \\
tex \midrule \\[-0.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: Marriage and \\ Homeownership (2010 Decennial)}} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Married} & \shortstack{Married \\ \\ White \\ \\ Spouse} &\shortstack{ Owner}\\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`married_2010_base_b'`married_2010_base_str' &`married_white_base_b'`married_white_base_str' &`owner_2010_base_b'`owner_2010_base_str'\\
tex &(`married_2010_base_se') &(`married_white_base_se') &(`owner_2010_base_se') \\\\
tex Control Mean &`married_2010_meansd_b' &`married_white_meansd_b' &`owner_2010_meansd_b' \\
tex Sample Size  &`married_2010_base_n' &`married_white_base_n' &`owner_2010_base_n' \\
tex \midrule \\[-0.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: Long-run \\ \\ Neighborhood \\ \\ (MAFARF 2019)}} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\ White} & \shortstack{Poverty \\ \\ Rate} \\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`m2019_pctblack_base_b'`m2019_pctblack_base_str' &`m2019_pctwhite_base_b'`m2019_pctwhite_base_str' &`m2019_povrate_base_b'`m2019_povrate_base_str'\\
tex &(`m2019_pctblack_base_se') &(`m2019_pctwhite_base_se') &(`m2019_povrate_base_se') \\\\
tex Control Mean &`m2019_pctblack_meansd_b' &`m2019_pctwhite_meansd_b' &`m2019_povrate_meansd_b' \\
tex Sample Size  &`m2019_pctblack_base_n' &`m2019_pctwhite_base_n' &`m2019_povrate_base_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close

///Response document table: parents table update with cummulative earnings
///Table 17: Parents with Cumulative Earnings
import delimited "$dir\Collinson_GAUMTO_Table8_LEHDHOH_T13_rounded.csv", clear 
tempfile leh
save `leh'

import delimited "$dir\Collinson_GAUMTO_Table11_CEN10HOH_T13_rounded.csv", clear 
append using `leh'
tempfile lehcen
save `lehcen'

import delimited "$dir\Collinson_GAUMTO_Table9_MAFARFHOH_T13_rounded.csv", clear 
append using `lehcen'

*keep what I need
keep if spec =="base" | spec =="meansd"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

*******************************
***** Appendix Table XVII *****
*******************************
texdoc init "$results\Supplementary_Table_17.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcccc} \toprule
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: Cumulative \\ \\ Earnings by...}} \\ \\[-1.75ex]
tex &\shortstack{Age 42} &\shortstack{Age 47} &\shortstack{Age 52} \\ \\[-2.5ex]
tex \midrule \\[-1.75ex]
tex 1(\% Black < 30) &`cumul_earn42_base_b'`cumul_earn42_base_str' &`cumul_earn47_base_b'`cumul_earn47_base_str' &`cumul_earn52_base_b'`cumul_earn52_base_str'\\
tex &(`cumul_earn42_base_se') &(`cumul_earn47_base_se') &(`cumul_earn52_base_se') \\\\
tex Control Mean &`cumul_earn42_meansd_b' &`cumul_earn47_meansd_b' &`cumul_earn52_meansd_b' \\
tex Sample Size &`cumul_earn42_base_n' &`cumul_earn47_base_n' &`cumul_earn52_base_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


**Appendix Table XI 
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded", clear 
	
*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** keep relevant observations
keep if inlist(group, "all")
keep if inlist(outcome, "sametractage28", "sametractparent2019")
keep if inlist(spec, "meansd", "notractfe", "nocont", "base")

* rename
replace outcome = "sametrct2019" if outcome == "sametractage28" 
replace outcome = "sametrct2019p" if outcome == "sametractparent2019" 

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof group, local(group)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
			
			foreach grox in `group' {
				local id3 = "`grox'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'" & ///
							group == "`grox'"
				local `id1'_`id3'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" & ///
							group == "`grox'"
				local 	`id1'_`id3'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'" & ///
								 group == "`grox'"
				local `id1'_`id3'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" & ///
									group == "`grox'", ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id3'_`id2'_str"	
				
						}
			}
}
*******************************
****** Appendix Table XI ******
*******************************	
texdoc init "$results/Supplementary_Table_11.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcc} \toprule
tex & (1) & (2) \\ \\[-1.5ex]
tex & \multicolumn{2}{c}{\shortstack{Outcome: \\ \\ 2019 Location Measures}} \\ 
tex \cmidrule{2-3} \\[-1.75ex]
tex & \shortstack{Same Tract \\ \\ as Placement} & \shortstack{Same Tract \\ \\ as Parents} \\
tex \midrule
tex $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`sametrct2019_all_base_b'`sametrct2019_all_base_str' &`sametrct2019p_all_base_b'`sametrct2019p_all_base_str' \\
tex & (`sametrct2019_all_base_se') & (`sametrct2019p_all_base_se') \\\\
tex Control Mean &`sametrct2019_all_meansd_b' &`sametrct2019p_all_meansd_b' \\
tex %Control SD & `sametrct2019_all_meansd_se' & `sametrct2019p_all_meansd_se' \\ 
tex Sample Size &`sametrct2019p_all_base_n' &`sametrct2019p_all_base_n' \\ 
tex \bottomrule
tex \end{tabular}%	
tex }
texdoc close	


**Appendix Table XIII

import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv",  varnames(2) clear 

* gen p values & stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** keep relevant observations
keep if source =="HR"
keep if outcome =="avgearn2428"
keep if inlist(spec, "incrank_incrank", "exp_ec_zip_exp_ec_zip")

*rename
replace outcome = "a2428" if outcome == "avgearn2428"
replace spec ="incrank" if spec =="incrank_incrank"
replace spec ="ec" if spec =="exp_ec_zip_exp_ec_zip"

** defining locals in loops 
levelsof outcome, local(outcome)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcome' {
	local id0 = "`outx'"
	
	foreach spex in `specs' {
		local id1 = "`spex'"
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_b = string(r(mean), "%9.0fc")
				
				sum se if outcome == "`outx'" & ///
							spec == "`spex'" 
				local `id0'_`id1'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id0'_`id1'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_str)
				di "`id0'_`id1'_str"
				
			}
}
*******************************
***** Appendix Table XIII *****
*******************************	
texdoc init "$results/Supplementary_Table_13.tex", replace force
tex \resizebox{\textwidth}{!}{	
tex \begin{tabular}{lccccc} \toprule 
tex & (1) &  & (2)  \\ \\[-1.75ex]
tex &  \multicolumn{3}{c}{\shortstack{Outcome: \\ \\ Earnings at Ages 24-28}}  \\ \\[-1.75ex]
tex \midrule
tex Income Rank (z-score)  & `a2428_incrank_b'`a2428_incrank_str' & &  \\
tex &(`a2428_incrank_se') & &  \\
tex Economic Connectedness (z-score) & &  & `a2428_ec_b'`a2428_ec_str'  \\
tex & &     &(`a2428_ec_se') \\ \\
tex Sample Size  & `a2428_incrank_n' & & `a2428_incrank_n' \\ \\[-1.5ex]
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close	



//Table 19: Household Fixed Effects Comparison

import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

*rename for locals
replace spec ="hhfe_byt" if spec =="hhfe_binary_youngerTreat"
replace spec ="hhfe_caxt" if spec =="hhfe_continuous_ageXtreat"
replace spec ="hhfe_byt_nc" if spec =="hhfe_binary_nocont_youngerTreat"
rename source sourcedata
replace sourcedata ="b" if sourcedata =="BASE"
replace sourcedata ="h" if sourcedata =="HHFE"

*keep what I need
keep if group =="all"
keep if spec =="hhfe_byt" | spec =="hhfe_caxt" | spec =="meansd" | spec =="hhfe_byt_nc"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof sourcedata, local(data)
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 

foreach data in `data'  {
	local id0 = "`data'"
	
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if sourcedata == "`data'" & ///
							outcome == "`outx'" & ///
							spec == "`spex'"
				local `id0'_`id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if sourcedata == "`data'" & ///	
							outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id0'_`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				levelsof stars if sourcedata == "`data'" & ///
									outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id0'_`id1'_`id2'_str)
				di "`id0'_`id1'_`id2'_str"		
				
				sum n_rounded if sourcedata == "`data'" & ///
								 outcome == "`outx'" & ///
								 spec == "`spex'",
				local `id0'_`id1'_`id2'_n = string(r(mean), "%9.0fc")
			}
}
}
*******************************
***** Appendix Table XIX ******
*******************************
texdoc init "$results\Supplementary_Table_19.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccccccc} \toprule 
tex &(1) &(2) &(3) &(4) &(5) &(6) \\ \\[-1.5ex]
tex & \multicolumn{6}{c}{Outcome: Earnings at...} \\
tex \cmidrule{2-7} \\[-1ex]
tex & \shortstack{Ages \\ \\ 24-28} & \shortstack{Ages \\ \\ 24-28} & \shortstack{Ages \\ \\ 26-28} & \shortstack{Ages \\ \\ 26-28} & \shortstack{Ages \\ \\ 29-33} & \shortstack{Ages \\ \\ 29-33} \\ \\[-1.75ex]
tex \midrule
tex 1(\% Black < 30) $\times$ 1(Younger) &`h_avgearn2428_hhfe_byt_b'`h_avgearn2428_hhfe_byt_str' &`h_avgearn2428_hhfe_byt_nc_b'`h_avgearn2428_hhfe_byt_nc_str' &`h_avgearn2628_hhfe_byt_b'`h_avgearn2628_hhfe_byt_str' &`h_avgearn2628_hhfe_byt_nc_b'`h_avgearn2628_hhfe_byt_nc_str' &`h_avgearn2933_hhfe_byt_b'`h_avgearn2933_hhfe_byt_str' &`h_avgearn2933_hhfe_byt_nc_b'`h_avgearn2933_hhfe_byt_nc_str' \\
tex &(`h_avgearn2428_hhfe_byt_se') &(`h_avgearn2428_hhfe_byt_nc_se') &(`h_avgearn2628_hhfe_byt_se') &(`h_avgearn2628_hhfe_byt_nc_se') &(`h_avgearn2933_hhfe_byt_se') &(`h_avgearn2933_hhfe_byt_nc_se')\\\\
tex Individual Controls &\cmark &\xmark & \cmark &\xmark  &\cmark &\xmark \\\\
tex Control Mean &`b_avgearn2428_meansd_b' &`b_avgearn2428_meansd_b' &`b_avgearn2628_meansd_b' &`b_avgearn2628_meansd_b' &`b_avgearn2933_meansd_b' &`b_avgearn2933_meansd_b'\\
tex Control SD &`b_avgearn2428_meansd_se' &`b_avgearn2428_meansd_se' &`b_avgearn2628_meansd_se' &`b_avgearn2628_meansd_se' &`b_avgearn2933_meansd_se' &`b_avgearn2933_meansd_se' \\
tex Sample Size &`h_avgearn2428_hhfe_caxt_n' &`h_avgearn2428_hhfe_caxt_n' &`h_avgearn2628_hhfe_caxt_n' &`h_avgearn2628_hhfe_caxt_n' &`h_avgearn2933_hhfe_caxt_n' &`h_avgearn2933_hhfe_caxt_n' \\ 
tex \hline \hline 
tex \end{tabular}%
tex }
texdoc close

//Table 20: Economic Oucomes Comparison: Base vs HHFE
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear
*keep what I need
keep if source =="BASE" | source =="HHFE"
keep if group =="all"
keep if spec =="base" | spec =="meansd" | spec =="basespec_hhfe_generalarea"
rename source sourcedata 
replace spec ="hhfe" if spec =="basespec_hhfe_generalarea"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

	
*******************************
***** Appendix Table XX *******
*******************************
	
texdoc init "$results\Supplementary_Table_20.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccc} \toprule 
tex &(1) &(2) \\ \\[-1.5ex]
tex & \shortstack{Earnings at \\ \\ Ages 24-28} & \shortstack{Earnings at \\ \\ Ages 24-28} \\ \\[-1.75ex]
tex \midrule
tex 1(\% Black < 30) &`avgearn2428_base_b'`avgearn2428_base_str' &`avgearn2428_hhfe_b'`avgearn2428_hhfe_str'\\
tex &(`avgearn2428_base_se') &(`avgearn2428_hhfe_se')\\\\
tex Household Fixed Effects & \xmark & \cmark \\\\
tex Sample Size &`avgearn2428_base_n' &`avgearn2428_hhfe_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


///Table X: Effects of Placement in White (Less Than 30% Black) Tracts on Earnings by Gender
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** drop stuff i dont need 
keep if inlist(group, "all", "boy", "girl")
keep if inlist(outcome, "earn24", "avgearn2428", "avgearn2933", "avgearn3438", "cumul_earn28", "cumul_earn33", "cumul_earn38")
keep if inlist(spec, "meansd", "base" )



** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof group, local(group)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach grox in `group' {
		local id2 = "`grox'"
	
		foreach spex in `specs' {
			local id3 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							group == "`grox'" & ///
							spec == "`spex'" 
				local `id1'_`id2'_`id3'_b = string(r(mean), "%9.0fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							group == "`grox'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_`id3'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 group == "`grox'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_`id3'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									group == "`grox'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_`id3'_str)
				di "`id1'_`id2'_`id3'_str"
				}
			}
}
	

*******************************
****** Appendix Table IX ******
*******************************	
	
texdoc init "$results\Supplementary_Table_9.tex", replace force
tex \begin{tabular}{lcccc} \toprule \\[-1.5ex]
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{Earnings Outcome:} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1ex]
tex &\shortstack{Ages \\ 24-28} & \shortstack{Ages \\ 29-33} & \shortstack{Ages \\ 34-38} \\ \\[-1.75ex]
tex \midrule   
tex Panel A. Full Sample \\ \\[-1.5ex]
tex \quad 1(\% Black < 30)  &`avgearn2428_all_base_b'`avgearn2428_all_base_str' &`avgearn2933_all_base_b'`avgearn2933_all_base_str' &`avgearn3438_all_base_b'`avgearn3438_all_base_str'\\
tex &(`avgearn2428_all_base_se') &(`avgearn2933_all_base_se') &(`avgearn3438_all_base_se')\\ \\
tex \quad Control Mean &`avgearn2428_all_meansd_b' &`avgearn2933_all_meansd_b' &`avgearn3438_all_meansd_b'\\
tex \quad Control SD &`avgearn2428_all_meansd_se' &`avgearn2933_all_meansd_se' &`avgearn3438_all_meansd_se'\\
tex \quad Sample Size & `avgearn2428_all_base_n' & `avgearn2933_all_base_n' & `avgearn3438_all_base_n'\\
tex \midrule
tex Panel B. Boys \\ \\[-1.5ex]
tex \quad 1(\% Black < 30)  &`avgearn2428_boy_base_b'`avgearn2428_boy_base_str' &`avgearn2933_boy_base_b'`avgearn2933_boy_base_str' &`avgearn3438_boy_base_b'`avgearn3438_boy_base_str'\\
tex &(`avgearn2428_boy_base_se') &(`avgearn2933_boy_base_se') &(`avgearn3438_boy_base_se')\\ \\
tex \quad Control Mean &`avgearn2428_boy_meansd_b' &`avgearn2933_boy_meansd_b' &`avgearn3438_boy_meansd_b'\\
tex \quad Control SD &`avgearn2428_boy_meansd_se' &`avgearn2933_boy_meansd_se' &`avgearn3438_boy_meansd_se'\\
tex \quad Sample Size & `avgearn2428_boy_base_n' & `avgearn2933_boy_base_n' & `avgearn3438_boy_base_n'\\
tex \midrule
tex Panel C. Girls \\ \\[-1.5ex]
tex \quad 1(\% Black < 30)  &`avgearn2428_girl_base_b'`avgearn2428_girl_base_str' &`avgearn2933_girl_base_b'`avgearn2933_girl_base_str' &`avgearn3438_girl_base_b'`avgearn3438_girl_base_str'\\
tex &(`avgearn2428_girl_base_se') &(`avgearn2933_girl_base_se') &(`avgearn3438_girl_base_se')\\ \\
tex \quad Control Mean &`avgearn2428_girl_meansd_b' &`avgearn2933_girl_meansd_b' &`avgearn3438_girl_meansd_b'\\
tex \quad Control SD &`avgearn2428_girl_meansd_se' &`avgearn2933_girl_meansd_se' &`avgearn3438_girl_meansd_se'\\
tex \quad Sample Size & `avgearn2428_girl_base_n' & `avgearn2933_girl_base_n' & `avgearn3438_girl_base_n'\\
tex \bottomrule
tex \end{tabular}%
texdoc close



/// Table 16: Household Head Mortality
import delimited "$dir\Collinson_GAUMTO3_Table3_NUMHOH_T13_rounded.csv", varnames(2) clear

replace group ="p60" if group =="age60plus"
replace outcome ="diedpc" if outcome =="died_precovid"
replace spec ="b" if spec =="base"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof group, local(group)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
		foreach g in `group' {
			local id3 ="`g'"
		
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'" & ///
							group =="`g'"
				local `id1'_`id2'_`id3'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" & ///
							group =="`g'"
				local 	`id1'_`id2'_`id3'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'" & ///
								 group =="`g'"
				local `id1'_`id2'_`id3'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" & ///
									group =="`g'", ///
				clean local(`id1'_`id2'_`id3'_str)
				di "`id1'_`id2'_`id3'_str"		
			}
}
}
*******************************
***** Appendix Table XVI ******
*******************************	

texdoc init "$results\Supplementary_Table_16.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccccccc} \toprule 
tex & (1) & (2) & (3) & (4) & (5) & (6) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{Full Sample} &\multicolumn{3}{c}{Age 60+} \\
tex \cmidrule(lr){2-4} \cmidrule(lr){5-7}\\[-1ex]
tex &\shortstack{Died} &\shortstack{Died \\ (Pre-Covid)} &\shortstack{Died \\ < Age 60} &\shortstack{Died} &\shortstack{Died \\ (Pre-Covid)} &\shortstack{Died \\ < Age 60} \\ \\ [-1.75ex]
tex \midrule
tex 1(Pct Black < 30\%) &`died_b_all_b'`died_b_all_str' &`diedpc_b_all_b'`diedpc_b_all_str' &`diedlt60_b_all_b'`diedlt60_b_all_str' &`died_b_p60_b'`died_b_all_str' &`diedpc_b_p60_b'`diedpc_b_p60_str' &`diedlt60_b_p60_b'`diedlt60_b_p60_str'\\
tex &(`died_b_all_se') &(`diedpc_b_all_se') &(`diedlt60_b_all_se') &(`died_b_p60_se') &(`diedpc_b_p60_se') &(`diedlt60_b_p60_se')\\\\
tex Sample Size &`died_b_all_n' &`diedpc_b_all_n' &`diedlt60_b_all_n' &`died_b_p60_n' &`diedpc_b_p60_n' &`diedlt60_b_p60_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


***Appendix Table V:
import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear 
tempfile c2010_data
save `c2010_data'

import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 
append using `c2010_data'


*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
*gen pval = 2*(normal(-(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** keep relevant observations
keep if inlist(outcome, "owner_2010", "own20172019", "avgown20172019")
keep if inlist(spec, "meansd", "notractfe", "nocont", "base")
keep if group=="35andolder"

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}
	
*******************************
***** Appendix Table V  *******
*******************************	
	
texdoc init "$results/Supplementary_Table_5.tex", replace force
tex \resizebox{\textwidth}{!}{	
tex \begin{tabular}{lccccccccc} \toprule \\[-1.5ex] 
tex & (1) & & (2) & & (3) & & (4) & & (5) \\ \\[-.75ex]
tex & \shortstack{Control \\ \\ Mean} & \multicolumn{7}{c}{Estimates} & \shortstack{Sample \\ \\ Size} \\ \\[-1.75ex]
tex \cmidrule{2-2} \cmidrule{4-8} \cmidrule{10-10}
tex Homeowner      &`owner_2010_meansd_b'`owner_2010_meansd_str' &   & `owner_2010_notractfe_b'`owner_2010_notractfe_str'  & & `owner_2010_nocont_b'`owner_2010_nocont_str' & &`owner_2010_base_b'`owner_2010_base_str' & & `owner_2010_nocont_n' \\
tex			&(`owner_2010_meansd_se') &	&(`owner_2010_notractfe_se') &	&(`owner_2010_nocont_se')&	&(`owner_2010_base_se')  \\ \\ [-1.5ex]
tex Ever In Owner-Occupied  & `own20172019_meansd_b'`own20172019_meansd_str' &   &  `own20172019_notractfe_b'`own20172019_notractfe_str' & & `own20172019_nocont_b'`own20172019_nocont_str' & & `own20172019_base_b'`own20172019_base_str' & &`own20172019_nocont_n' \\
tex			& (`own20172019_meansd_se') &	& (`own20172019_notractfe_se') &	&(`own20172019_nocont_se')&	&(`own20172019_base_se')   \\ \\ [-1.5ex]
tex Frac. Yrs. in Owner-Occupied & `avgown20172019_meansd_b'`avgown20172019_meansd_str' &  &  `avgown20172019_notractfe_b'`avgown20172019_notractfe_str'  & & `avgown20172019_nocont_b'`avgown20172019_nocont_str' &  & `avgown20172019_base_b'`avgown20172019_base_str' & & `avgown20172019_nocont_n' \\
tex			&(`avgown20172019_meansd_se') &	&(`avgown20172019_notractfe_se') &	&(`avgown20172019_nocont_se') &	&(`avgown20172019_base_se')  \\ \\ [.5ex]
tex Specification Includes: & & & & & & & & & \\ \\[-2.25ex]
tex \quad Cohort FE & & & \cmark & & \cmark & & \cmark & & \\
tex \quad Tract FE & & & \xmark & & \cmark & & \cmark & & \\
tex \quad Individual Controls & & & \xmark & & \xmark & & \cmark & & \\
tex \bottomrule 	
tex \end{tabular}%	
tex }
texdoc close	



***Appendix Table VI:
import delimited "$dir\Collinson_GAUMTO_Table3_CEN00KIDS_T13_rounded.csv", clear 
tempfile c2000_data
save `c2000_data'

import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 
append using `c2000_data'


*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** keep relevant observations
keep if inlist(group, "all")
drop if inlist(outcome, "m2010_incrnk_black", "m2019_incrnk_black", "m26_incrnk_black", "m28_incrnk_black", "sametractparent2019")
keep if inlist(spec, "meansd", "notractfe", "nocont", "base")


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}
	
*******************************
***** Appendix Table VI *******
*******************************	
	
	
texdoc init "$results/Supplementary_Table_6.tex", replace force
tex \resizebox{\textwidth}{!}{		
tex \begin{tabular}{lccccccccc} \toprule
tex & (1) &  & (2) & &(3)& &(4)& &(5) \\ \\[-.75ex]
tex & \shortstack{Control \\ \\ Mean} & \multicolumn{7}{c}{Estimates} & \shortstack{Sample \\ \\ Size} \\ \\[-1.75ex]
tex \cmidrule{2-2} \cmidrule{4-8} \cmidrule{10-10} \\[-1.75ex]
tex 2019 MAF-ARF Characteristic: & & & & & &  & & \\ \\[-1.5ex]
tex \quad Share Black    & `m2019_pctblack_meansd_b'`m2019_pctblack_meansd_str' &  & `m2019_pctblack_notractfe_b'`m2019_pctblack_notractfe_str' & & `m2019_pctblack_nocont_b'`m2019_pctblack_nocont_str'  & & `m2019_pctblack_base_b'`m2019_pctblack_base_str' & & `m2019_pctblack_base_n' \\
tex	&(`m2019_pctblack_meansd_se')&	&(`m2019_pctblack_notractfe_se') &	&(`m2019_pctblack_nocont_se') &	&(`m2019_pctblack_base_se') \\ \\[-1.5ex]
tex \quad Share White  & `m2019_pctwhite_meansd_b'`m2019_pctwhite_meansd_str' &   &  `m2019_pctwhite_notractfe_b'`m2019_pctwhite_notractfe_str' & & `m2019_pctwhite_nocont_b'`m2019_pctwhite_nocont_str' & & `m2019_pctwhite_base_b'`m2019_pctwhite_base_str' & & `m2019_pctwhite_base_n' \\
tex & (`m2019_pctwhite_meansd_se') &	& (`m2019_pctwhite_notractfe_se') &	&(`m2019_pctwhite_nocont_se')&	&(`m2019_pctwhite_base_se') \\ \\[-1.5ex]
tex \quad Poverty Rate & `m2019_povrate_meansd_b'`m2019_povrate_meansd_str' &  &  `m2019_povrate_notractfe_b'`m2019_povrate_notractfe_str'  & & `m2019_povrate_nocont_b'`m2019_povrate_nocont_str' &  & `m2019_povrate_base_b'`m2019_povrate_base_str' & & `m2019_povrate_base_n' \\
tex &(`m2019_povrate_meansd_se') & & (`m2019_povrate_notractfe_se')& &(`m2019_povrate_nocont_se') & & (`m2019_povrate_base_se') \\ \\[-1.5ex]
tex \quad Later-life Income Rank & `m2019_incrnk_meansd_b' &  &  `m2019_incrnk_notractfe_b'`m2019_incrnk_notractfe_str'  & & `m2019_incrnk_nocont_b'`m2019_incrnk_nocont_str' &  & `m2019_incrnk_base_b'`m2019_incrnk_base_str' & & `m2019_incrnk_base_n' \\
tex &(`m2019_incrnk_meansd_se') & & (`m2019_incrnk_notractfe_se')& &(`m2019_incrnk_nocont_se') & & (`m2019_incrnk_base_se')  \\ \\[-1.5ex]
tex Specification Includes: & & & & & & & & & \\ \\[-2.25ex]
tex \quad Cohort FE & & & \cmark & & \cmark & & \cmark & & \\
tex \quad Tract FE & & & \xmark & & \cmark & & \cmark & & \\
tex \quad Individual Controls & & & \xmark & & \xmark & & \cmark & & \\ \\[-1.5ex]
tex \bottomrule
tex \end{tabular}%	
tex }
texdoc close		
	

	
	
***Appendix Table VII:
import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear 

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** drop stuff i dont need 
*keep if inlist(group, "35andolder")
keep if inlist(outcome, "married_2010", "married_white")
keep if inlist(group, "all")
keep if inlist(spec, "meansd", "notractfe", "nocont", "base")


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}
	
	
*******************************
***** Appendix Table VII ******
*******************************	
	
texdoc init "$results/Supplementary_Table_7.tex", replace force
tex \resizebox{\textwidth}{!}{		
tex \begin{tabular}{lccccccccc} \toprule 
tex & (1) & & (2) & & (3) & & (4) & & (5) \\ \\[-1.75ex]
tex & \shortstack{Control \\ Mean} & \multicolumn{7}{c}{Estimates} & N \\ \\[-1.75ex]
tex \cmidrule{2-2} \cmidrule{4-8} \cmidrule{10-10}
tex Married     &`married_2010_meansd_b'`married_2010_meansd_str' &   & `married_2010_notractfe_b'`married_2010_notractfe_str'  & & `married_2010_nocont_b'`married_2010_nocont_str' & &`married_2010_base_b'`married_2010_base_str' & & `married_2010_base_n' \\
tex &(`married_2010_meansd_se') &	&(`married_2010_notractfe_se') &	&(`married_2010_nocont_se')&	&(`married_2010_base_se') \\ \\[-1.5ex]
tex Married White Spouse & `married_white_meansd_b'`married_whitec2000_shwhite_meansd_str' &  & `married_white_notractfe_b'`married_white_notractfe_str' & & `married_white_nocont_b'`married_white_nocont_str'  & & `married_white_base_b'`married_white_base_str' & & `married_white_base_n' \\
tex &(`married_white_meansd_se')&	&(`married_white_notractfe_se') &	&(`married_white_nocont_se') &	&(`married_white_base_se') & \\ \\[-.5ex]
tex Specification Includes: & & & & & & & & & \\ \\[-2.25ex]
tex \quad Cohort FE & & & \cmark & & \cmark & & \cmark & & \\
tex \quad Tract FE & & & \xmark & & \cmark & & \cmark & & \\
tex \quad Individual Controls & & & \xmark & & \xmark & & \cmark & & \\ \\[-1.5ex]
tex \hline \hline
tex \end{tabular}%	
tex }
texdoc close		


***Appendix Table XII:
import delimited "$dir\Collinson_GAUMTO_Table5_NUMKIDS_T13_rounded.csv", clear 

tempfile table5 
save `table5'

import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear
append using `table5'

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01


** keep relevant observations 
keep if inlist(group, "all", "boy", "girl")
keep if inlist(outcome, "died", "incar_2010")
keep if inlist(spec, "meansd", "base" )


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof group, local(group)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach grox in `group' {
		local id2 = "`grox'"
	
		foreach spex in `specs' {
			local id3 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							group == "`grox'" & ///
							spec == "`spex'" 
				local `id1'_`id2'_`id3'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							group == "`grox'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_`id3'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 group == "`grox'" & ///
								 spec == "`spex'" 
				local `id1'_`id2'_`id3'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									group == "`grox'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_`id3'_str)
				di "`id1'_`id2'_`id3'_str"
				}
			}
}

*******************************
***** Appendix Table XII ******
*******************************	

texdoc init "$results/Supplementary_Table_12.tex", replace force
tex \resizebox{\textwidth}{!}{	
tex \begin{tabular}{lcc} \toprule \\[-1.5ex]
tex & (1) & (2) \\ \\[-1.5ex]
tex &\multicolumn{2}{c}{Outcome:} \\ \\[-2.5ex]
tex \cmidrule{2-3} \\[-1ex]
tex &\shortstack{Mortality} & \shortstack{Incarceration} \\ \\[-1.75ex]
tex \midrule
tex Panel A. Full Sample \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`died_all_base_b'`died_all_base_str' &  `incar_2010_all_base_b'`incar_2010_all_base_str' \\
tex & (`died_all_base_se') & (`incar_2010_all_base_se') \\ \\
tex \quad Control Mean &`died_all_meansd_b'`died_all_meansd_str' & `incar_2010_all_meansd_b'`incar_2010_all_meansd_str' \\
tex \quad Sample Size & `incar_2010_all_base_n' & `incar_2010_all_base_n' \\
tex \midrule
tex Panel B. Boys \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`died_boy_base_b'`died_boy_base_str'  & `incar_2010_boy_base_b'`incar_2010_boy_base_str' \\
tex & (`died_boy_base_se') & (`incar_2010_boy_base_se')\\ \\
tex \quad Control Mean &`died_boy_meansd_b'`died_boy_meansd_str' & `incar_2010_boy_meansd_b'`incar_2010_boy_meansd_str' \\
tex \quad Sample Size & `incar_2010_boy_base_n' & `incar_2010_boy_base_n' \\
tex \midrule
tex Panel C. Girls \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`died_girl_base_b'`died_girl_base_str' & `incar_2010_girl_base_b'`incar_2010_girl_base_str' \\
tex & (`died_girl_base_se') & (`incar_2010_girl_base_se')\\ \\
tex \quad Control Mean &`died_girl_meansd_b'`died_girl_meansd_str' & `incar_2010_girl_meansd_b'`incar_2010_girl_meansd_str' \\
tex \quad Sample Size & `incar_2010_girl_base_n' & `incar_2010_girl_base_n' \\
tex \bottomrule
tex \end{tabular}%	
tex }
texdoc close

***Appendix Table XVIII:
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** keep relevant observations
keep if inlist(group, "all")
keep if inlist(outcome, "m2019_pctblack", "m2019_pctwhite", "m2019_povrate", "m2019_incrnk")
keep if inlist(spec, "base", "parenttract2019" )

* rename
replace spec = "pt" if spec== "parenttract2019" 


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof group, local(group)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

*******************************
**** Appendix Table XVIII *****
*******************************	
	
texdoc init "$results/Supplementary_Table_18.tex", replace force
tex \resizebox{\textwidth}{!}{		
tex \begin{tabular}{lcccc}
tex \toprule
tex & (1) & (2) & (3) & (4) \\ \\[-1.5ex]
tex & \multicolumn{4}{c}{\shortstack{Outcome: Later-life \\ \\ Neighborhood (MAF-ARF 2019)}} \\
tex \cmidrule{2-5} \\[-1ex]
tex & \shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\ White} & \shortstack{Poverty \\ \\ Rate} & \shortstack{Later-life \\ \\ Income \\ \\ Rank} \\ \\[-1.75ex]
tex \midrule
tex Panel A. Gautreaux Base Sample \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ & `m2019_pctblack_base_b'`m2019_pctblack_base_str' & `m2019_pctwhite_base_b'`m2019_pctwhite_base_str' & `m2019_povrate_base_b'`m2019_povrate_base_str' &`m2019_incrnk_base_b'`m2019_incrnk_base_str' \\
tex & (`m2019_pctblack_base_se') & (`m2019_pctwhite_base_se') & (`m2019_povrate_base_se') & (`m2019_incrnk_base_se') \\
tex Panel B. Gautreaux Sample Excluding Living in Parent Tracts \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`m2019_pctblack_pt_b'`m2019_pctblack_pt_str' & `m2019_pctwhite_pt_b'`m2019_pctwhite_pt_str' & `m2019_povrate_pt_b'`m2019_povrate_pt_str' & `m2019_incrnk_pt_b'`m2019_incrnk_pt_str' \\
tex & (`m2019_pctblack_pt_se') & (`m2019_pctwhite_pt_se') & (`m2019_povrate_pt_se') & (`m2019_incrnk_pt_se') \\
tex \bottomrule
tex \end{tabular}	
tex }
texdoc close	
	

***Appendix Table XXI:
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded", clear 

* keep relevant observations
keep if inlist(group, "all")
keep if inlist(outcome, "m2019_pctblack", "m2019_incrnk")
keep if inlist(spec, "base", "Robustness: 1stoffer", "Robustness: exclude90", "Robustness: include70", "Robustness: lowvac", "Robustness: suburb")

* rename
replace spec = "fst_offer" if spec == "Robustness: 1stoffer"
replace spec = "exclude90" if spec == "Robustness: exclude90"
replace spec = "include70" if spec == "Robustness: include70"
replace spec = "lowvac" if spec == "Robustness: lowvac"
replace spec = "suburb" if spec == "Robustness: suburb"

	
tempfile mafarf
save `mafarf'	
	
	
import delimited "$dir\Collinson_GAUMTO_Table1_LEHDKIDS_T13_rounded.csv", clear 

* keep relevant observations
keep if inlist(group, "all")
keep if inlist(outcome, "earn24", "avgearn2428")
keep if inlist(spec, "base", "Robustness: 1stoffer", "Robustness: exclude90", "Robustness: include70", "Robustness: lowvac", "Robustness: suburb")

* rename
replace spec = "fst_offer" if spec == "Robustness: 1stoffer"
replace spec = "exclude90" if spec == "Robustness: exclude90"
replace spec = "include70" if spec == "Robustness: include70"
replace spec = "lowvac" if spec == "Robustness: lowvac"
replace spec = "suburb" if spec == "Robustness: suburb"

append using `mafarf'



* gen p values & stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
*gen pval = 2*(normal(-(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
	
				sum se if outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"
				
			}
}
	


	
* no decimals 
global y "earn24 avgearn2428"
global sp "base exclude90 fst_offer include70 lowvac suburb"
global s "LEHD"

foreach i in $s {   
foreach x in $y {
	
	foreach z in $sp  {
		
		sum beta if sourcedata == "`i'" & ///
					outcome == "`x'" & ///
					spec == "`z'"
		global `x'_`z'_b : di string(r(mean), "%9.0fc")
		
		sum se if sourcedata == "`i'" & ///
					outcome == "`x'" & ///
					spec == "`z'"
		global `x'_`z'_se : di string(r(mean), "%9.0fc")
	} 
	 		
}
}

*******************************
***** Appendix Table XII ******
*******************************
	
texdoc init "$results/Supplementary_Table_12.tex", replace force
tex \resizebox{\textwidth}{!}{		
tex \begin{tabular}{lcccccccccccc} \toprule \\[-1.5ex]
tex  & &(1)   & &(2)    & &(3)   & &(4)  & &(5)  & &(6)     \\ \\[-.75ex]
tex  & &\multicolumn{11}{c}{Alternative Specifications/Samples:}  \\ 
tex  \cmidrule{3-13} \\[-1.75ex]
tex  & &\shortstack{Base}  & & \shortstack{First \\ Offer}  & & \shortstack{Exclude \\ 1990s}  & & \shortstack{Include \\ 1970s}  & & \shortstack{Low \\ Vacancy}  & & \shortstack{Suburb}  \\
tex  \midrule
tex Earnings at Age 24 &    &${earn24_base_b}`earn24_base_str' &   & ${earn24_fst_offer_b}`earn24_fst_offer_str'  & & ${earn24_exclude90_b}`earn24_exclude90_str' & &${earn24_include70_b}`earn24_include70_str' & &${earn24_lowvac_b}`earn24_lowvac_str' & & ${earn24_suburb_b}`earn24_suburb_str' \\
tex		&	&(${earn24_base_se}) &	&(${earn24_fst_offer_se}) &	&(${earn24_exclude90_se})&	&(${earn24_include70_se}) & & (${earn24_lowvac_se}) & &(${earn24_suburb_se}) \\ 
tex		&	&[N=`earn24_base_n'] &	&[N=`earn24_fst_offer_n'] &	&[N=`earn24_exclude90_n']&	&[N=`earn24_include70_n'] & & [N=`earn24_lowvac_n'] & &[N=`earn24_suburb_n'] \\ \\[-1.5ex]
tex Earnings at Age 24-28 &    &${avgearn2428_base_b}`avgearn2428_base_str' &   & ${avgearn2428_fst_offer_b}`avgearn2428_fst_offer_str'  & & ${avgearn2428_exclude90_b}`avgearn2428_exclude90_str' & &${avgearn2428_include70_b}`avgearn2428_include70_str' & &${avgearn2428_lowvac_b}`avgearn2428_lowvac_str' & & ${avgearn2428_suburb_b}`avgearn2428_suburb_str' \\
tex		&	&(${avgearn2428_base_se}) &	&(${avgearn2428_fst_offer_se}) &	&(${avgearn2428_exclude90_se})&	&(${avgearn2428_include70_se}) & & (${avgearn2428_lowvac_se}) & &(${avgearn2428_suburb_se}) \\ 
tex		&	&[N=`avgearn2428_base_n'] &	&[N=`avgearn2428_fst_offer_n'] &	&[N=`avgearn2428_exclude90_n']&	&[N=`avgearn2428_include70_n'] & & [N=`avgearn2428_lowvac_n'] & &[N=`avgearn2428_suburb_n'] \\ \\[-1.5ex]
tex MAF-ARF 2019, Share Black &     &`m2019_pctblack_base_b'`m2019_pctblack_base_str' &   & `m2019_pctblack_fst_offer_b'`m2019_pctblack_fst_offer_str'  & & `m2019_pctblack_exclude90_b'`m2019_pctblack_exclude90_str' & &`m2019_pctblack_include70_b'`m2019_pctblack_include70_str' & &`m2019_pctblack_lowvac_b'`m2019_pctblack_lowvac_str' & & `m2019_pctblack_suburb_b'`m2019_pctblack_suburb_str' \\
tex	&		&(`m2019_pctblack_base_se') &	&(`m2019_pctblack_fst_offer_se') &	&(`m2019_pctblack_exclude90_se')&	&(`m2019_pctblack_include70_se') & & (`m2019_pctblack_lowvac_se') & &(`m2019_pctblack_suburb_se') \\ 
tex		&	&[N=`m2019_pctblack_base_n'] &	&[N=`m2019_pctblack_fst_offer_n'] &	&[N=`m2019_pctblack_exclude90_n']&	&[N=`m2019_pctblack_include70_n'] & & [N=`m2019_pctblack_lowvac_n'] & &[N=`m2019_pctblack_suburb_n'] \\ \\[-1.5ex]
tex MAF-ARF 2019, Inc. Rank in Adulthood &    &`m2019_incrnk_base_b'`m2019_incrnk_base_str' &   & `m2019_incrnk_fst_offer_b'`m2019_incrnk_fst_offer_str'  & & `m2019_incrnk_exclude90_b'`m2019_incrnk_exclude90_str' & &`m2019_incrnk_include70_b'`m2019_incrnk_include70_str' & &`m2019_incrnk_lowvac_b'`m2019_incrnk_lowvac_str' & & `m2019_incrnk_suburb_b'`m2019_incrnk_suburb_str' \\
tex		&	&(`m2019_incrnk_base_se') &	&(`m2019_incrnk_fst_offer_se') &	&(`m2019_incrnk_exclude90_se')&	&(`m2019_incrnk_include70_se') & & (`m2019_incrnk_lowvac_se') & &(`m2019_incrnk_suburb_se') \\ 
tex		&	&[N=`m2019_incrnk_base_n'] &	&[N=`m2019_incrnk_fst_offer_n'] &	&[N=`m2019_incrnk_exclude90_n']&	&[N=`m2019_incrnk_include70_n'] & & [N=`m2019_incrnk_lowvac_n'] & &[N=`m2019_incrnk_suburb_n'] \\ \\[-1.5ex]
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close	


***Appendix Table XXIV:
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 

* keep relevant observations
keep if inlist(group, "all")
keep if inlist(outcome, "m26_pctblack", "m26_pctwhite", "m26_povrate", "m26_incrnk", "m2019_pctblack", "m2019_pctwhite", "m2019_povrate", "m2019_incrnk")
keep if inlist(spec, "base")

*rename
rename group group_gau
rename beta beta_gau
rename se se_gau
rename r2 r2_gau 
rename n_rounded n_rounded_gau 
rename descoutcome descoutcome_gau
tempfile mafarfkids
save `mafarfkids'

import delimited "$dir\Collinson_GAUMTO_Table13_MAFARFMTO_T13_rounded.csv", clear 
keep if inlist(group, "black")
keep if inlist(outcome, "m26_pctblack", "m26_pctwhite", "m26_povrate", "m26_incrnk", "m2019_pctblack", "m2019_pctwhite", "m2019_povrate", "m2019_incrnk")
keep if inlist(spec, "base")

merge m:1 outcome  using `mafarfkids'
drop _merge 

	
	// GAU - MTO 
gen gau_mto = beta_gau - beta 

gen se_diff = sqrt(se^2 + se_gau^2)
gen pval = (2*ttail(n_rounded + n_rounded_gau - 4, abs(gau_mto/se_diff)) )
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01


	//pval just for MTO 
gen pval_mto = (2*ttail(n_rounded-1, abs(beta/se)))
gen strs_mto =  "*" if pval_mto <= 0.1 & pval_mto > 0.05
replace strs_mto = "**" if pval_mto <= 0.05 & pval_mto > 0.01
replace strs_mto = "***" if pval_mto <= 0.01
	
	//pval just for GAU 
gen pval_gau = (2*ttail(n_rounded_gau-1, abs(beta_gau/se_gau)))
gen strs_gau = "*" if pval_gau <= 0.1 & pval_gau > 0.05
replace strs_gau = "**" if pval_gau <= 0.05 & pval_gau > 0.01
replace strs_gau = "***" if pval_gau <= 0.01


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof group, local(group)
levelsof stars, local(stars)
levelsof strs_mto, local(strs_m)



 

	// MTO 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'" 
				local `id1'_blk_`id2'_b = string(r(mean), "%9.3fc")
				
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'"  
				local 	`id1'_blk_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_blk_`id2'_n = string(r(mean), "%9.0fc")	
				
				levelsof strs_mto if outcome == "`outx'" & ///
								spec == "`spex'", ////
				clean local(`id1'_blk_`id2'_strs)
				di "`id1'_blk_`id2'_strs"
				
				// differences 
				sum gau_mto if outcome == "`outx'" & ///
								spec == "`spex'" 
				local `id1'_`id2'_diff = string(r(mean), "%9.3fc")
				
				sum se_diff if outcome == "`outx'" & ///
								spec == "`spex'"
				local `id1'_`id2'_se = string(r(mean), "%9.3fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , /// 
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"
				
				//pvals 
				sum pval if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_p = string(r(mean), "%9.3fc")
					
				
			}
			
}
	
	
	
	//GAU 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta_gau, local(beta_g)
levelsof se_gau, local(serror_g)
levelsof group_gau, local(group_g)
levelsof strs_gau, local(strs_g)


	// GAU
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
				
				sum beta_gau if outcome == "`outx'" & ///
							spec == "`spex'" 
				local `id1'_all_`id2'_b = string(r(mean), "%9.3fc")
				
				sum se_gau if 	outcome == "`outx'" & ///
							spec == "`spex'"  
				local 	`id1'_all_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded_gau if outcome == "`outx'" & ///
									 spec == "`spex'"
				local `id1'_all_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof strs_gau if outcome == "`outx'" & ///
									spec == "`spex'", ///
				clean local(`id1'_all_`id2'_strs)
				di "`id1'_all_`id2'_strs"
						
				
			}
			
}
*******************************
***** Appendix Table XXIV *****
*******************************

texdoc init "$results/Supplementary_Table_24.tex", replace force
tex \resizebox{\textwidth}{!}{	
tex \begin{tabular}{lcccc}
tex \toprule
tex & (1) & (2) & (3) & (4) \\ \\[-1.5ex]
tex & \multicolumn{4}{c}{\shortstack{Outcome: Later-life \\ Neighborhood (MAF-ARF at Age 26)}} \\
tex \cmidrule{2-5} \\[-1ex]
tex & \shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\  White} & \shortstack{Poverty \\ \\ Rate} & \shortstack{Later-life \\ \\ Income \\ \\ Rank} \\ \\[-1.75ex]
tex \midrule
tex Panel A. Gautreaux \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`m26_pctblack_all_base_b'`m26_pctblack_all_base_strs' &`m26_pctwhite_all_base_b'`m26_pctwhite_all_base_strs' & `m26_povrate_all_base_b'`m26_povrate_all_base_strs' & `m26_incrnk_all_base_b'`m26_incrnk_all_base_strs' \\
tex & (`m26_pctblack_all_base_se') & (`m26_pctwhite_all_base_se') & (`m26_povrate_all_base_se') & (`m26_incrnk_all_base_se') \\\\[-1.5ex]
tex \quad Sample Size & `m26_pctblack_all_base_n' & `m26_pctblack_all_base_n' & `m26_pctblack_all_base_n' & `m26_pctblack_all_base_n' \\\\
tex Panel B. MTO \\ \\[-1.5ex]
tex \quad $\mathit{TakeExp_i}$ & `m26_pctblack_blk_base_b'`m26_pctblack_blk_base_strs' &`m26_pctwhite_blk_base_b'`m26_pctwhite_blk_base_strs' & `m26_povrate_blk_base_b'`m26_povrate_blk_base_strs' & `m26_incrnk_blk_base_b'`m26_incrnk_blk_base_strs' \\
tex & (`m26_pctblack_blk_base_se') & (`m26_pctwhite_blk_base_se') & (`m26_povrate_blk_base_se') & (`m26_incrnk_blk_base_se') \\\\[-1.5ex]
tex \quad Sample Size & `m26_pctblack_blk_base_n' & `m26_pctblack_blk_base_n' & `m26_pctblack_blk_base_n' & `m26_pctblack_blk_base_n' \\\\
tex Estimated Diff. &`m26_pctblack_base_diff'`m26_pctblack_base_str' & `m26_pctwhite_base_diff'`m26_pctwhite_base_str' &`m26_povrate_base_diff'`m26_povrate_base_str' &`m26_incrnk_base_diff'`m26_incrnk_base_str' \\
tex & (`m26_pctblack_base_se') & (`m26_pctwhite_base_se') & (`m26_povrate_base_se') & (`m26_incrnk_base_se') \\
tex \bottomrule
tex \end{tabular}
tex }
texdoc close
	

///Table 8: Average Employment 
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

*keep what I need 
keep if inlist(outcome, "avgemply2428", "avgemply2933", "avgemply3438") 

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

*******************************
***** Appendix Table VIII *****
*******************************	

texdoc init "$results\Supplementary_Table_8.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcccc} \toprule 
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: \\ Frac. Years Employed at...}} \\ \\[-2.5ex]
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Ages \\ 24-28} & \shortstack{Ages \\ 29-33} & \shortstack{Ages \\ 34-38} \\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`avgemply2428_base_b'`avgemply2428_base_str' &`avgemply2933_base_b'`avgemply2933_base_str' &`avgemply3438_base_b'`avgemply3438_base_str'\\
tex &(`avgemply2428_base_se') &(`avgemply2933_base_se') &(`avgemply3438_base_se')\\\\
tex Control Mean &`avgemply2428_meansd_b' &`avgemply2933_meansd_b' &`avgemply3438_meansd_b'\\
tex Control SD &`avgemply2428_meansd_se' &`avgemply2933_meansd_se' &`avgemply3438_meansd_se'\\
tex Sample Size &`avgemply2428_base_n' &`avgemply2933_base_n' &`avgemply3438_base_n'\\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


///Table 18: Average Earnings
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

*keep what I need
keep if inlist(outcome, "avgearn2428", "avgearn2933", "avgearn3438")
keep if source =="BASE"
keep if group =="all"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.0fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

*******************************
****** Appendix Table IV ******
*******************************	

texdoc init "$results\Supplementary_Table_4.tex", replace force
tex \begin{tabular}{lccccccccc} \toprule
tex & \shortstack{Control \\ Mean} & \multicolumn{7}{c}{Estimates} & N \\ \\[-1.75ex]
tex & (1) &  & (2) & &(3)& &(4)& &(5) \\ \\[-1.75ex]
tex \cmidrule{2-2} \cmidrule{4-8} \cmidrule{10-10} \\[-1.75ex]
tex \textbf{Panel A:} Earnings At Age(s): & & & & & &  & & & \\ \\[-1.75ex]
tex \quad Age 24-28 & `avgearn2428_meansd_b'&  &`avgearn2428_notractfe_b'`avgearn2428_notractfe_str'& &`avgearn2428_nocont_b'`avgearn2428_nocont_str'& & `avgearn2428_base_b'`avgearn2428_base_str'&  &`avgearn2428_base_n' \\
tex &(`avgearn2428_meansd_se')&	&(`avgearn2428_notractfe_se')&	&(`avgearn2428_nocont_se')&	&(`avgearn2428_base_se')& & \\ \\[-1.5ex]
tex \quad Age 29-33 & `avgearn2933_meansd_b'& &`avgearn2933_notractfe_b'`avgearn2933_notractfe_str'& &`avgearn2933_nocont_b'`avgearn2933_nocont_str'& & `avgearn2933_base_b'`avgearn2933_base_str'& &`avgearn2933_base_n' \\
tex	&(`avgearn2933_meansd_se')& &(`avgearn2933_notractfe_se')& &(`avgearn2933_nocont_se')& &(`avgearn2933_base_se')& & \\ \\[-1.5ex]
tex \quad Age 34-38 &`avgearn3438_meansd_b'&  &`avgearn3438_notractfe_b'`avgearn3438_notractfe_str'& &`avgearn3438_nocont_b'`avgearn3438_nocont_str'& & `avgearn3438_base_b'`avgearn3438_base_str'&  &`avgearn3438_base_n' \\
tex	&(`avgearn3438_meansd_se') &	&(`avgearn3438_notractfe_se') &	&(`avgearn3438_nocont_se')& &(`avgearn3438_base_se')& & \\ \\[-1.5ex]
tex Specification Includes: & & & & & & & & & \\ \\[-2.25ex]
tex \quad Cohort FE & & & \cmark & & \cmark & & \cmark & & \\
tex \quad Tract FE & & & \xmark & & \cmark & & \cmark & & \\
tex \quad Individual Controls & & & \xmark & & \xmark & & \cmark & & \\ \\[-1.5ex]
tex \hline \hline 
tex \end{tabular}%
texdoc close



///Table 15: Controlling for Schooling
import delimited "$dir\Collinson_GAUMTO3_Table1_LEHDKIDS_T13_rounded.csv", varnames(2) clear

keep if source == "BASE" | source =="SCHOOLS"
keep if outcome =="avgearn2428"
keep if group =="all"

replace spec ="ga_earn_ratio" if spec =="generalarea_v_sch_pupil_pertch_generalarea"
replace spec ="ga_earn_spend" if spec =="generalarea_v_sch_exp_perstd_generalarea"
replace spec ="ga_ratio" if spec =="generalarea_v_sch_pupil_pertch_sch_pupil_pertch"
replace spec ="ga_spend" if spec =="generalarea_v_sch_exp_perstd_sch_exp_perstd"

keep if inlist(spec, "base", "ga_earn_ratio", "ga_earn_spend", "ga_ratio", "ga_spend")

* gen p values & stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

local specs1 "ga_earn_spend base ga_earn_ratio ga_ratio"
local specs2 "ga_spend"

	// beta 

foreach spex in `specs1' {
		local id1 = "`spex'"
		
				
				sum beta if spec == "`spex'"
				local `id1'_b = string(r(mean), "%9.0fc")
				
		
				sum se if spec == "`spex'" 
				local `id1'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if spec == "`spex'"
				local `id1'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if spec == "`spex'" , ///
				clean local(`id1'_str)
				di "`id1'_str"		
			}

// beta 

foreach spex in `specs2' {
		local id1 = "`spex'"
		
				
				sum beta if spec == "`spex'"
				local `id1'_b = string(r(mean), "%9.3fc")
				
		
				sum se if spec == "`spex'" 
				local `id1'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if spec == "`spex'"
				local `id1'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if spec == "`spex'" , ///
				clean local(`id1'_str)
				di "`id1'_str"		
			}


*******************************
****** Appendix Table XV ******
*******************************	

texdoc init "$results\Supplementary_Table_15", replace force
tex \begin{tabular}{lcccc} \toprule \\[-1.5ex]
tex &  \multicolumn{3}{c}{Outcome: Earnings Age 24-28}  \\ \\[-1.75ex]
tex &(1) &(2) &(3) \\ \\[-1.75ex]
tex \cmidrule{2-4}  \\ \\[-1.75ex]  
tex 1(Placement Tract <30\% Black)  &`base_b'`base_str' &`ga_earn_ratio_b'`ga_earn_ratio_str' &`ga_earn_spend_b'`ga_earn_spend_str'\\
tex &(`base_se') &(`ga_earn_ratio_se') &(`ga_earn_spend_se') \\ \\[-1.75ex]
tex Pupil per Teacher Ratio & &`ga_ratio_b'`ga_ratio_str' & \\
tex & &(`ga_ratio_se') & \\ \\[-1.75ex]
tex Spending per Pupil & & &`ga_spend_b'`ga_spend_str'   \\
tex & & &(`ga_spend_se') \\ \\[-1.75ex]
tex \quad N &`base_n'  & `base_n' &`base_n' \\
tex \bottomrule
tex \end{tabular}%
texdoc close


///Updated Appendix A.5 to Table 4 Format
/// Table 20: Neighborhood Comparison

import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear 
tempfile c2010_data
save `c2010_data'

*adding p value and stars 
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 
append using `c2010_data'


*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** drop stuff i dont need 
keep if inlist(group, "all")
drop if inlist(outcome, "m2010_incrnk_black", "m2019_incrnk_black", "m26_incrnk_black", "m28_incrnk_black", "sametractparent2019")
keep if inlist(spec, "meansd", "base")


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}


*******************************
****** Appendix Table X *******
*******************************	
	
texdoc init "$results\Supplementary_Table_10.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccc} \toprule \\
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: Later-life \\ \\ Neighborhood (Decennial 2010)}}\\ 
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\ White} & \shortstack{Poverty \\ \\ Rate}\\ \\[-2.5ex]
tex \midrule \\[-1.75ex]
tex 1(\% Black < 30) &`c2010_shblack_base_b'`c2010_shblack_base_str' & `c2010_shwhite_base_b'`c2010_shwhite_base_str' &`c2010_povrate_base_b'`c2010_povrate_base_str'\\
tex &(`c2010_shblack_base_se') &(`c2010_shwhite_base_se') &(`c2010_povrate_base_se')\\\\
tex Control Mean &`c2010_shblack_meansd_b' &`c2010_shwhite_meansd_b' &`c2010_povrate_meansd_b'\\
tex Sample Size &`c2010_shblack_base_n' &`c2010_shwhite_base_n' &`c2010_povrate_base_n'\\
tex \midrule \\[-0.5ex]
tex &\multicolumn{3}{c}{\shortstack{Outcome: Later-life \\ \\ Neighborhood (MAFARF 2010)}} \\ 
tex \cmidrule{2-4} \\[-1.75ex]
tex &\shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\ White} & \shortstack{Poverty \\ \\ Rate}\\ \\[-2.5ex]
tex \midrule
tex 1(\% Black < 30) &`m2010_pctblack_base_b'`m2010_pctblack_base_str' & `m2010_pctwhite_base_b'`m2010_pctwhite_base_str' & `m2010_povrate_base_b'`m2010_povrate_base_str'\\
tex &(`m2010_pctblack_base_se') &(`m2010_pctwhite_base_se') &(`m2010_povrate_base_se') \\\\
tex Control Mean &`m2010_pctblack_meansd_b' &`m2010_pctwhite_meansd_b' & `m2010_povrate_meansd_b'\\
tex Sample Size &`m2010_pctblack_base_n'  &`m2010_pctwhite_base_n' & `m2010_povrate_base_n'\\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


///New Table from Balance Data
import delimited "$dir\Collinson_GAUMTO3_Table2_BALKIDS_T13_rounded.csv", varnames(2) clear 

*keep what I need
keep if inlist(outcome, "prearn24", "prm2019_pctblack")

*need to create a new outcome so that the decimals will work for the control mean on earnings
replace outcome ="mean_prearn24" if spec =="meansd" & outcome =="prearn24"

replace spec ="shwhite" if spec =="std_place_shwhite"
replace spec ="shblk" if spec =="std_place_shafam"
replace spec ="prate" if spec =="std_place_povrate"

*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)

local outcomes1 "prearn24 prm2019_pctblack"
local outcomes2 "mean_prearn24"

// beta 
foreach outx in `outcomes1' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}

// beta 
foreach outx in `outcomes2' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.0fc")
				
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.0fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"		
			}
}


*******************************
****** Appendix Table I *******
*******************************	

texdoc init "$results\Supplementary_Table_1.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lccc} \toprule 
tex & (1) & (2) \\ \\[-1.5ex]
tex &\multicolumn{2}{c}{Outcome:} \\ \\[-2.5ex]
tex \cmidrule{2-3} \\[-1ex]
tex &\shortstack{Predicted \\ \\ Earnings \\ \\ at Age 24} & \shortstack{ Predicted \\ \\ Tract Share \\ \\ Black (2019)} \\ \\[-1.75ex]
tex \midrule   
tex Share White (\$z\$-score) &`prearn24_shwhite_b' &`prm2019_pctblack_shwhite_b'\\
tex &(`prearn24_shwhite_se') &(`prm2019_pctblack_shwhite_se') \\\\
tex Control Mean &`mean_prearn24_meansd_b' &`prm2019_pctblack_meansd_b' \\
tex Sample Size &`prearn24_shwhite_n' &`prm2019_pctblack_shwhite_n' \\
tex \midrule
tex Share Black (\$z\$-score) &`prearn24_shblk_b' &`prm2019_pctblack_shblk_b'\\
tex &(`prearn24_shblk_se') &(`prm2019_pctblack_shblk_se') \\\\
tex Control Mean &`mean_prearn24_meansd_b' &`prm2019_pctblack_meansd_b' \\
tex Sample Size &`prearn24_shblk_n' &`prm2019_pctblack_shblk_n'\\
tex \midrule 
tex Poverty Rate (\$z\$-score) &`prearn24_prate_b' &`prm2019_pctblack_prate_b'\\
tex &(`prearn24_prate_se') &(`prm2019_pctblack_prate_se') \\\\
tex Control Mean &`mean_prearn24_meansd_b' &`prm2019_pctblack_meansd_b' \\
tex Sample Size &`prearn24_prate_n' &`prm2019_pctblack_prate_n'\\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close



///Horse Race for Married White Spouse

import delimited "$dir\Collinson_GAUMTO2_Table3_CEN10KIDS_T13_rounded", clear 

** drop stuff i dont need 
keep if inlist(outcome, "married_white")
keep if inlist(indepvar, "povrate", "shwhite")
keep if inlist(spec, "povrate", "shwhite", "povrate_v_shwhite")

* gen p values & stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01



** defining locals in loops 
levelsof indepvar, local(indepvar)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach indepx in `indepvar' {
	local id1 = "`indepx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
				
				sum beta if indepvar == "`indepx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_b = string(r(mean), "%9.3fc")
				
				sum se if indepvar == "`indepx'" & ///
							spec == "`spex'" 
				local 	`id1'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if indepvar == "`indepx'" & ///
								 spec == "`spex'"
				local `id1'_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof stars if indepvar == "`indepx'" & ///
									spec == "`spex'" , ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"
				
			}
}
*******************************
***** Appendix Table XIV ******
*******************************	

texdoc init "$results\Supplementary_Table_14.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcccc} \toprule 
tex & (1) & (2) & (3) \\ \\[-1.5ex]
tex & \multicolumn{3}{c}{\shortstack{Outcome: \\ \\Married White Spouse}} \\ \\[-2.5ex]
tex \midrule 
tex Share White (\$z\$-score) &`shwhite_shwhite_b'`shwhite_shwhite_str' & &`shwhite_povrate_v_shwhite_b'`shwhite_povrate_v_shwhite_str'\\
tex &(`shwhite_shwhite_se') & &(`shwhite_povrate_v_shwhite_se') \\
tex Poverty Rate (\$z\$-score) & &`povrate_povrate_b'`povrate_povrate_str' &`povrate_povrate_v_shwhite_b'`povrate_povrate_v_shwhite_str' \\
tex & &(`povrate_povrate_se') &(`povrate_povrate_v_shwhite_se') \\\\
tex Sample Size &`shwhite_shwhite_n' &`povrate_povrate_n' &`povrate_povrate_v_shwhite_n' \\
tex \bottomrule
tex \end{tabular}%
tex }
texdoc close


**Appendix Table XXIII
import delimited "$dir\Collinson_GAUMTO_Table2_MAFARFKIDS_T13_rounded.csv", clear 

* keep relevant observations 
keep if inlist(group, "all")
keep if inlist(outcome, "m26_pctblack", "m26_pctwhite", "m26_povrate", "m26_incrnk", "m2019_pctblack", "m2019_pctwhite", "m2019_povrate", "m2019_incrnk")
keep if inlist(spec, "base")

*renaming
rename group group_gau
rename beta beta_gau
rename se se_gau
rename r2 r2_gau 
rename n_rounded n_rounded_gau 
rename descoutcome descoutcome_gau
tempfile mafarfkids
save `mafarfkids'

import delimited "$dir\Collinson_GAUMTO_Table13_MAFARFMTO_T13_rounded.csv", clear 
keep if inlist(group, "black")
keep if inlist(outcome, "m26_pctblack", "m26_pctwhite", "m26_povrate", "m26_incrnk", "m2019_pctblack", "m2019_pctwhite", "m2019_povrate", "m2019_incrnk")
keep if inlist(spec, "base")

merge m:1 outcome  using `mafarfkids'
drop _merge 

	
	// GAU - MTO 
gen gau_mto = beta_gau - beta 

gen se_diff = sqrt(se^2 + se_gau^2)
gen pval = (2*ttail(n_rounded + n_rounded_gau - 4, abs(gau_mto/se_diff)) )
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01


	//pval just for MTO 
gen pval_mto = (2*ttail(n_rounded-1, abs(beta/se)))
gen strs_mto =  "*" if pval_mto <= 0.1 & pval_mto > 0.05
replace strs_mto = "**" if pval_mto <= 0.05 & pval_mto > 0.01
replace strs_mto = "***" if pval_mto <= 0.01
	
	//pval just for GAU 
gen pval_gau = (2*ttail(n_rounded_gau-1, abs(beta_gau/se_gau)))
gen strs_gau = "*" if pval_gau <= 0.1 & pval_gau > 0.05
replace strs_gau = "**" if pval_gau <= 0.05 & pval_gau > 0.01
replace strs_gau = "***" if pval_gau <= 0.01


** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof se, local(serror)
levelsof group, local(group)
levelsof stars, local(stars)
levelsof strs_mto, local(strs_m)

 

	// MTO 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'" 
				local `id1'_blk_`id2'_b = string(r(mean), "%9.3fc")
				
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'"  
				local 	`id1'_blk_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'"
				local `id1'_blk_`id2'_n = string(r(mean), "%9.0fc")	
				
				levelsof strs_mto if outcome == "`outx'" & ///
								spec == "`spex'", ////
				clean local(`id1'_blk_`id2'_strs)
				di "`id1'_blk_`id2'_strs"
				
				// differences 
				sum gau_mto if outcome == "`outx'" & ///
								spec == "`spex'" 
				local `id1'_`id2'_diff = string(r(mean), "%9.3fc")
				
				sum se_diff if outcome == "`outx'" & ///
								spec == "`spex'"
				local `id1'_`id2'_se = string(r(mean), "%9.3fc")
				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" , /// 
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"
				
				//pvals 
				sum pval if outcome == "`outx'" & ///
							spec == "`spex'"
				local `id1'_`id2'_p = string(r(mean), "%9.3fc")
					
				
			}
			
}
	
	
	
	//GAU 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta_gau, local(beta_g)
levelsof se_gau, local(serror_g)
levelsof group_gau, local(group_g)
levelsof strs_gau, local(strs_g)


	// GAU
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
				
				sum beta_gau if outcome == "`outx'" & ///
							spec == "`spex'" 
				local `id1'_all_`id2'_b = string(r(mean), "%9.3fc")
				
				sum se_gau if 	outcome == "`outx'" & ///
							spec == "`spex'"  
				local 	`id1'_all_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded_gau if outcome == "`outx'" & ///
									 spec == "`spex'"
				local `id1'_all_`id2'_n = string(r(mean), "%9.0fc")
				
				levelsof strs_gau if outcome == "`outx'" & ///
									spec == "`spex'", ///
				clean local(`id1'_all_`id2'_strs)
				di "`id1'_all_`id2'_strs"
						
				
			}
			
}
*******************************
**** Appendix Table XXIII *****
*******************************	

texdoc init "$results/Supplementary_Table_23.tex", replace force
tex \resizebox{\textwidth}{!}{
tex \begin{tabular}{lcccc}
tex \toprule
tex & (1) & (2) & (3) & (4) \\ \\[-1.5ex]
tex & \multicolumn{4}{c}{\shortstack{Outcome: Later-life \\ Neighborhood (MAF-ARF 2019)}} \\
tex \cmidrule{2-5} \\[-1ex]
tex & \shortstack{Share \\ \\ Black} & \shortstack{Share \\ \\ White} & \shortstack{Poverty \\ \\ Rate} & \shortstack{Later-life \\ \\ Income \\ \\ Rank} \\ \\[-1.75ex]
tex \midrule
tex Panel A. Gautreaux \\ \\[-1.5ex]
tex \quad $1(\mathit{Share Black_{d(i)}} < 0.30)$ &`m2019_pctblack_all_base_b'`m2019_pctblack_all_base_strs' & `m2019_pctwhite_all_base_b'`m2019_pctwhite_all_base_strs' &`m2019_povrate_all_base_b'`m2019_povrate_all_base_strs' &`m2019_incrnk_all_base_b'`m2019_incrnk_all_base_strs' \\
tex & (`m2019_pctblack_all_base_se') & (`m2019_pctwhite_all_base_se') & (`m2019_povrate_all_base_se') & (`m2019_incrnk_all_base_se') \\\\[-1.5ex]
tex \quad Sample Size & `m2019_pctblack_all_base_n' & `m2019_pctblack_all_base_n' & `m2019_pctblack_all_base_n' & `m2019_pctblack_all_base_n' \\\\
tex Panel B. MTO \\ \\[-1.5ex]
tex \quad $\mathit{TakeExp_i}$ &`m2019_pctblack_blk_base_b'`m2019_pctblack_blk_base_strs' &`m2019_pctwhite_blk_base_b'`m2019_pctwhite_blk_base_strs' &`m2019_povrate_blk_base_b'`m2019_povrate_blk_base_strs' & `m2019_incrnk_blk_base_b'`m2019_incrnk_blk_base_strs' \\ 
tex &  (`m2019_pctblack_blk_base_se') & (`m2019_pctwhite_blk_base_se') & (`m2019_povrate_blk_base_se') & (`m2019_incrnk_blk_base_se') \\\\[-1.5ex]
tex \quad Sample Size &`m2019_pctblack_blk_base_n' &`m2019_pctblack_blk_base_n' &`m2019_pctblack_blk_base_n' &`m2019_pctblack_blk_base_n' \\ \\
tex Estimated Diff. &`m2019_pctblack_base_diff'`m2019_pctblack_base_str' &`m2019_pctwhite_base_diff'`m2019_pctwhite_base_str' & `m2019_povrate_base_diff'`m2019_povrate_base_str' & `m2019_incrnk_base_diff'`m2019_incrnk_base_str' \\
tex & (`m2019_pctblack_base_se')   & (`m2019_pctwhite_base_se')  & (`m2019_povrate_base_se') & (`m2019_incrnk_base_se') \\
tex \bottomrule
tex \end{tabular}
tex }
texdoc close	


*******************************************************************************

	// Table 25. Census Matching 


import delimited "$dir\Collinson_GAUMTO_Table6_ATTRITKIDS_T13_rounded.csv", clear 
tempfile attrikids
save `attrikids'

import delimited "$dir\Collinson_GAUMTO_Table4_CEN10KIDS_T13_rounded.csv", clear 
append using `attrikids'


*adding p value and stars 
gen pval = (2*ttail(n_rounded-1, abs(beta/se)))
gen stars = "*" if pval <= 0.1 & pval > 0.05
replace stars = "**" if pval <= 0.05 & pval > 0.01
replace stars = "***" if pval <= 0.01

** drop stuff i dont need 
keep if inlist(group, "all", "kids", "35andolder")
keep if inlist(outcome, "haspik", "hascensus2010", "has2010tract", "has2019tract", "hasage26tract", "refheadsps")
keep if inlist(spec, "meansd", "base")

* renaming to make shorter 
replace group = "35" if group == "35andolder"

** defining locals in loops 
levelsof outcome, local(outcomes)
levelsof spec, local(specs)
levelsof beta, local(beta)
levelsof group, local(group)
levelsof se, local(serror)
levelsof stars, local(stars)


	// beta 
foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach spex in `specs' {
		local id2 = "`spex'"
			
			foreach grox in `group' {
				local id3 = "`grox'"
		
				
				sum beta if outcome == "`outx'" & ///
							spec == "`spex'" & ///
							group == "`grox'"
				local `id1'_`id3'_`id2'_b = string(r(mean), "%9.3fc")
				
		
				sum se if 	outcome == "`outx'" & ///
							spec == "`spex'" & ///
							group == "`grox'"
				local 	`id1'_`id3'_`id2'_se = string(r(mean),"%9.3fc")
				
				sum n_rounded if outcome == "`outx'" & ///
								 spec == "`spex'" & ///
								 group == "`grox'"
				local `id1'_`id3'_`id2'_n = string(r(mean), "%9.0fc")
 				
				levelsof stars if outcome == "`outx'" & ///
									spec == "`spex'" & ///
									group == "`grox'", ///
				clean local(`id1'_`id2'_str)
				di "`id1'_`id2'_str"	
				
						}
			}
}
	
*******************************
***** Appendix Table XXV ******
*******************************	
	
texdoc init "$results\Supplementary_Table_25.tex", replace force
tex \begin{tabular}{lccccccc} \toprule \\[-1.5ex]
tex & \multicolumn{7}{c}{\textit{Outcomes:}} \\ \\[-1.75ex]
tex & \shortstack{Has \\ PIK} &  & \shortstack{Has \\ PIK}  & & \shortstack{Has 2010 \\ Census} & & \shortstack{Has 2010 \\ MAFARF} \\ \\[-1.75ex] 
tex  & (1) &  & (2) & &(3)& &(4)  \\ \\[-1.75ex]
tex   \cmidrule{2-2} \cmidrule{4-4} \cmidrule{6-6} \cmidrule{8-8} \\
tex 1(\text{Tract Black}<30\%)     &`haspik_all_base_b'`haspik_all_base_str' &   & `haspik_kids_base_b'`haspik_kids_base_str'  & & `hascensus2010_kids_base_b'`hascensus2010_kids_base_str' & &`has2010tract_kids_base_b'`has2010tract_kids_base_str' \\
tex			&(`haspik_all_base_se') &	&(`haspik_kids_base_b') &	&(`hascensus2010_kids_base_se')&	&(`has2010tract_kids_base_se') \\ \\[-1.5ex]
tex N &`haspik_all_base_n' & &`haspik_kids_base_n' & &`hascensus2010_kids_base_n' & &`has2010tract_kids_base_n' \\ \\[-1.5ex] 
tex Sample & All   & & Children & & Had PIK & & Had PIK \\ \\[-1.5ex]
tex Dep. Var Mean &`haspik_all_meansd_b' & &`haspik_kids_meansd_b' & &`hascensus2010_kids_meansd_b' & &`has2010tract_kids_meansd_b' \\ 
tex Tract FE & \cmark & & \cmark & & \cmark & & \cmark \\
tex Individual Controls & \xmark & & \xmark & & \xmark & & \xmark \\
tex & \multicolumn{7}{c}{\textit{Outcomes:}} \\ \\[-1.75ex]
tex & \shortstack{Has 2019 \\ MAFARF Tract} & & \shortstack{Has Age 26 \\ MAFARF Tract} & & \shortstack{Head or Spouse \\ in Census 2010} &  & \shortstack{Head or Spouse \\ in Census 2010} \\ \\[-1.75ex]
tex & (5) & & (6)& &(7) & & (8) \\ \\[-1.75ex]
tex \cmidrule{2-2} \cmidrule{4-4} \cmidrule{6-6} \cmidrule{8-8} \\
tex 1(\text{Tract Black}<30\%) & `has2019tract_kids_base_b'`has2019tract_kids_base_str' &   &  `hasage26tract_kids_base_b'`hasage26tract_kids_base_str' & & `refheadsps_all_base_b'`refheadsps_all_base_str' & & `refheadsps_35_base_b'`refheadsps_35_base_str' \\
tex			& (`has2019tract_kids_base_se') &	& (`hasage26tract_kids_base_se') &	&(`refheadsps_all_base_se')&	&(`refheadsps_35_base_se')  \\ \\[-1.5ex]
tex N & `has2019tract_kids_base_n'& & `hasage26tract_kids_base_n' & & `refheadsps_all_base_n' & & `refheadsps_35_base_n'  \\ \\[-1.5ex]
tex Sample & Had PIK & & Had PIK & & In Census & & \shortstack{In Census: \\ Age 35+} \\ \\[-1.5ex]
tex Dep. Var Mean &`has2019tract_kids_meansd_b' &  &`hasage26tract_kids_meansd_b'& & `refheadsps_all_meansd_b' & &`refheadsps_35_meansd_b' \\
tex Tract FE & \cmark & & \cmark & & \cmark & & \cmark \\
tex Individual Controls & \xmark & & \xmark & & \xmark & & \xmark \\
tex \hline \hline 
tex \end{tabular}%
texdoc close
